<template>
	<view
		:style="{
			'background': nodeModel.background,
			'marginTop': nodeModel.marginTop+'rpx',
			'marginBottom': nodeModel.marginBottom+'rpx',
			'marginLeft': nodeModel.marginLeft+'rpx',
			'marginRight': nodeModel.marginLeft+'rpx',
		}">
		<u-notice-bar :direction='nodeModel.direction' :text='text' :speed="nodeModel.speed" :duration="nodeModel.duration" :color='nodeModel.colorForText1' :fontSize="nodeModel.fontsizeForText1+'rpx'" @click='itemHandle'></u-notice-bar>
	</view>
</template>

<script>
	import { common } from '@/api/common.js'
	export default{
		name: 'jc-noticebar',
		props: {
			nodeModel: {
				type: Object,
				default: {}
			},
			noticeText: {
				type: [Array, String],
				default: ()=>[]
			}
		},
		data() {
			return {
				text: null
			}
		},
		watch:{
			noticeText: {
				immediate : true,
				deep: true,
				handler(val){
					if(this.nodeModel.options1 == 'dynamic'){
						this.text = val
					}
				}
			},
			nodeModel: {
				immediate : true,
				deep: true,
				handler(val){
					if(this.nodeModel.options1 == 'static'){
						if(this.nodeModel.direction == 'row'){
							var text=''
							for(var i=0;i<this.nodeModel.advertList.length;i++){
								text = text + this.nodeModel.advertList[i].title
							}
							this.text = text
						}else if(this.nodeModel.direction == 'column'){
							var text = []
							for(var i=0;i<this.nodeModel.advertList.length;i++){
								text.push(this.nodeModel.advertList[i].title)
							}
							this.text = text
						}
					}
				}
			}
		},
		methods:{
			getHomeNoticeText() {
				common.operateActionPost(this.nodeModel.query, {}).then(res => {
					if (res.data.code == 10000) {
						if(this.nodeModel.direction == 'row'){
							this.text = res.data.data.textList[0]
						}else if(this.nodeModel.direction == 'column'){
							this.text = res.data.data.textList
						}
					}
				})
			},
			itemHandle(e){
				console.log('点击通知', this.nodeModel)
				// this.$emit('itemHandle', e)
				var filterModel = this.$tools.paramsToObj(this.nodeModel.filter)
				if(filterModel.openshop == 'test_v'){
					var that = this
					uni.showModal({
						title: '将要返回琼楼科技官方小程序',
						success(res) {
							if(res.confirm){
								that.$Router.replaceAll({
									name: 'home',
									params: {
										openshop: that.$store.state.demoOpenshop
									}
								})
							}
						}
					})
				}
			},
		}
	}
</script>

<style>
</style>
